<?php
session_start();
require('../check_login.php');
include(dirname(__FILE__) . '/../config.php');
require_once('supports_lib.php');
if (isset($_GET['id'])) {
    $a_contact = get_support_detail($_GET['id']);
}
if (isset($_POST['go'])) {
    update_support($_POST);
}
require_once('../header.php');
?>

<!-- BEGIN CONTAINER -->
<div class="page-container">
    <!-- BEGIN SIDEBAR -->
    <?php require_once('../left_menu.php'); ?>
    <!-- END SIDEBAR -->
    <!-- BEGIN CONTENT -->
    <div class="page-content-wrapper">
        <div class="page-content">
            <!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->

            <!-- /.modal -->
            <!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
            <!-- BEGIN STYLE CUSTOMIZER -->

            <!-- END STYLE CUSTOMIZER -->
            <!-- BEGIN PAGE HEADER-->
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->

                    <ul class="page-breadcrumb breadcrumb">

                        <li>
                            <i class="fa fa-home"></i>
                            <a href="<? echo $url ;?>/dashboard.php">
                                Trang chủ
                            </a>
                            <i class="fa fa-angle-right"></i>
                        </li>
                        <li>
                            <a href="<?php echo $url; ?>/support/supports.php">
                                Danh sách các vấn đề cần giải quyết
                            </a>
                            <i class="fa fa-angle-right"></i>
                        </li>
                        <li>
                            <a href="add_support.php">
                                Tạo mới
                            </a>
                            <i class="fa fa-angle-right"></i>
                        </li>

                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT-->
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption">
                        <i class="fa fa-reorder"></i>Form nhập liệu
                    </div>

                </div>
                <div class="portlet-body form">
                    <!-- BEGIN FORM-->
                    <form id ='form_edit_support' class="horizontal-form" method="post" action="edit_support_detail.php">
                        <div class="form-body">
                            <h3 class="form-section">Thông tin chung</h3>
                            <div class="row">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="control-label">Tiêu đề
                                            <span class="required">*</span>
                                        </label>
                                        <input type="text" value="<?php echo (isset($a_contact['support_name']) ? $a_contact['support_name'] : '') ?>" class="form-control" id="support_name" name="support_name">
                                        <input type="hidden" name="id" value="<?php echo (isset($a_contact['id']) ? $a_contact['id'] : '') ?>"/>
                                    </div>
                                </div>

                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="control-label">Người phụ trách

                                        </label>
                                        <?php
                                        include_once(dirname(__FILE__) . '/../user/users_lib.php');
                                        $users = get_all_users();
                                        ?>
                                        <select name="assigned_to" tabindex="" class="form-control">
                                            <option <?php echo ((isset($a_contact) && $a_contact['assigned_to'] == '0') ? 'selected="selected"' : '') ?> value="0">
                                                --Chưa chọn--
                                            </option>
                                            <?php foreach ($users as $user) { ?>
                                                <option <?php echo ((isset($a_contact) && $a_contact['assigned_to'] == $user['id']) ? 'selected="selected"' : '') ?> value="<?php echo $user['id'] ?>">
                                                    <?php echo $user['first_name'] . " " . $user['last_name'] ?>
                                                </option>
                                            <?php } ?>
                                        </select>    

                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="control-label">Tình trạng

                                        </label>

                                        <select name="status" tabindex="" class="form-control">
                                            <option <?php echo ((isset($a_contact) && $a_contact['status'] == 1) ? 'selected="selected"' : '') ?> value="1">Tạo mới</option>
                                            <option <?php echo ((isset($a_contact) && $a_contact['assigned_to'] == 2) ? 'selected="selected"' : '') ?> value="2">Đang được xử lý</option>
                                            <option <?php echo ((isset($a_contact) && $a_contact['assigned_to'] == 3) ? 'selected="selected"' : '') ?> value="3">Đã được giải quyết</option>
                                        </select>    

                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label class="control-label">Thuộc sản phẩm

                                        </label>

                                        <?php
                                        include_once(dirname(__FILE__) . '/../product/products_lib.php');
                                        $products = get_all_products();
                                        ?>
                                        <select name="product_id" tabindex="" class="form-control">
                                            <option value="--None--">
                                                --Chưa chọn--
                                            </option>
                                            <?php foreach ($products as $product) { ?>
                                                <option <?php echo ((isset($a_contact) && $a_contact['product_id'] == $product['id']) ? 'selected="selected"' : '') ?> value="<?php echo $product['id'] ?>">
                                                    <?php echo $product['product_name'] ?>
                                                </option>
                                            <?php } ?>
                                        </select>   
                                    </div>
                                </div>


                            </div>


                            <!--/row-->
                            <h3 class="form-section">Mô tả chung</h3>
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">

                                        <textarea name="description" rows="3" class="form-control">
                                            <?php echo (isset($a_contact['description']) ? $a_contact['description'] : '') ?>                                            

                                        </textarea>
                                    </div>
                                </div>

                            </div>

                            <!--/row-->

                        </div>
                        <div class="form-actions right">
                            <button class="btn default" type="button">Hủy</button>
                            <button class="btn blue" type="submit" name="go"><i class="fa fa-check"></i> Lưu</button>
                        </div>
                    </form>
                    <!-- END FORM-->
                </div>
            </div>
            <a class="btn default" id="auto_fire_when_edit_ok">

            </a>
            <!-- END PAGE CONTENT -->
        </div>
    </div>
    <!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<?php
require_once('../footer.php');
require_once('../common_script.php');
?>
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="<?php echo $url ?>/assets/scripts/core/app.js"></script>
<script src="<?php echo $url ?>/js/add_support_validation.js"></script>
<script src="<?php echo $url ?>/js/add_support_alert_dialog.js"></script>
<script>
    jQuery(document).ready(function () {
        // initiate layout and plugins
        App.init();
        FormAddContactValidation.init();
        UIAlertDialogApi.init();
<?php
if (isset($_POST['go'])) {
    ?>
            $('#auto_fire_when_edit_ok').click();

    <?php
}
?>
    });
</script>
</body>
<!-- END BODY -->
</html>